package org.example.test;

import java.util.Vector;

/**
 * @author Jimmy
 * @version 1.0
 */
public class Demo {
    public static void main(String[] args) {
        int[] nums ={-1,0,3,5,9,12};
        int search = search(nums, 9);
        System.out.println(search);
        System.out.println(6/2);
    }


    public static int search(int[] nums, int target) {
        int min = 0;
        int max = nums.length-1;
        while(min <= max){
            int middle = (min + max)/2;
            if (target == nums[middle]) {
                return middle;
                //判断下限
            } else if (target < nums[middle]) {
                max = middle - 1;
                //判断上限
            } else {
                min = middle + 1;
            }
        }
        return -1;
    }
}
